import { fetchData } from '@/services/name';
import effects from './effects';
import listeners from './listeners';
export default {
  namespace: 'users',
  state: {
    name: 'A',
    lis: '',
  },
  effects: {
    ...effects,
    ...listeners,
  },
  // effects: {
  //     * fetchUserName({ payload }: any, { call, put, seclect }: any) {
  //         const response = yield call(fetchData);
  //         const callName = response.data[0].author;
  //         yield put({ type: 'callsetName', payload: callName })
  //     },
  // fetchUserName:[
  //     function *({ payload }: any, { call, put,seclect }: any) {
  //         const response = yield call(fetchData);
  //         const callName = response.data[0].author;
  //         yield put({ type: 'callsetName', payload: callName })
  //     },{type:'takeEvery'}
  // ]
  // },
  reducers: {
    setName(state: any, { payload }: any) {
      return {
        ...state,
        name: payload,
      };
    },
    callsetName(state: any, { payload }: any) {
      return {
        ...state,
        name: payload,
      };
    },
    clear(state: any, { payload }: any) {
      return {
        ...state,
        lis: '1',
      };
    },
  },
  subscriptions: {
    //监听clearname
    setup({ dispatch }: any) {
      dispatch({
        type: 'clearname',
      });
    },
  },
};
